package model.utils;

import com.example.towerdefence.R;

import controller.GameBoard;
import controller.GameBoardActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

public class PauseMenuDialog {

	private static boolean mute;

	public static void createMsgDialog(final Context context,
			final GameBoard gameBoard) {
		LayoutInflater layoutPauseMenu = LayoutInflater.from(context);
		View pauseMenuView = layoutPauseMenu.inflate(
				R.layout.pause_dialog_menu, null);

		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
				context);
		alertDialogBuilder.setTitle("Settings");
		alertDialogBuilder.setView(pauseMenuView);

		final Button restartBtn = (Button) pauseMenuView
				.findViewById(R.id.restartBtn);
		restartBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent startMenuIntent = new Intent(context,
						GameBoardActivity.class);
				context.startActivity(startMenuIntent);
				System.exit(0);
			}
		});

		final ToggleButton soundToggle = (ToggleButton) pauseMenuView
				.findViewById(R.id.soundsBtn);

		soundToggle.setChecked(mute);
		soundToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (isChecked) {
					mute = true;
				} else {
					mute = false;
				}
			}
		});

		alertDialogBuilder
				.setCancelable(false)
				.setPositiveButton("OK",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.dismiss();
							}
						})
				.setNegativeButton("Exit",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
								android.os.Process
										.killProcess(android.os.Process.myPid());
								System.exit(0);
							}
						});

		AlertDialog alertDialog = alertDialogBuilder.create();
		alertDialog.show();
	}

	public static boolean isMute() {
		return mute;
	}
}
